package org.sang.service;/*
 * @author  gaokecheng
 * @date 2019/9/9 18:14
 *
 *
 * */

import org.sang.bean.CurrentOnline;
import org.sang.common.FinalString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OnlineService {
    @Autowired
    private RedisTemplate redisTemplate;
    public Map<String,Object> getCurrentOnline(){
            List<CurrentOnline> list =  new ArrayList<>();
            int count = 0;
        if(redisTemplate.hasKey(FinalString.CURRENT_USERS)){
            list= (List<CurrentOnline>) redisTemplate.opsForValue().get(FinalString.CURRENT_USERS);
        }
        if(redisTemplate.hasKey(FinalString.CURRENT_COUNT)){
         count= (int) redisTemplate.opsForValue().get(FinalString.CURRENT_COUNT);
        }
        Map<String, Object> map= new HashMap();
        map.put("list",list);
        map.put("count",count);
        return map;
    }
}
